﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IBindServiceExtensions.cs" company="">
//   
// </copyright>
// <summary>
//   The i bind service extensions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Bindings
{
    using System;

    /// <summary>
    ///   The i bind service extensions.
    /// </summary>
    public static class IBindServiceExtensions
    {
        #region Public Methods and Operators

        /// <summary>
        /// The bind.
        /// </summary>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="obj1">
        /// The obj 1. 
        /// </param>
        /// <param name="obj2">
        /// The obj 2. 
        /// </param>
        /// <returns>
        /// The <see cref="IBinding"/> . 
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        public static IBinding Bind(this IBindService service, object obj1, object obj2)
        {
            IBinding binding;
            if (!service.TryBind(obj1, obj2, out binding))
            {
                throw new Exception("Can't bind " + obj1 + " to " + obj2);
            }

            return binding;
        }

        /// <summary>
        /// The unbind.
        /// </summary>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="obj1">
        /// The obj 1. 
        /// </param>
        /// <param name="obj2">
        /// The obj 2. 
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public static void Unbind(this IBindService service, object obj1, object obj2)
        {
            if (!service.TryUnbind(obj1, obj2))
            {
                throw new Exception("Can't unbind " + obj1 + " from " + obj2);
            }
        }

        /// <summary>
        /// The unbind.
        /// </summary>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="obj">
        /// The obj. 
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public static void Unbind(this IBindService service, object obj)
        {
            if (!service.TryUnbind(obj))
            {
                throw new Exception("Can't unbind " + obj);
            }
        }

        #endregion
    }
}